home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Science / MathPad 2.1.5 / examples / falling < prev    next >
Text File  |  1993-09-20  |  908b  |  27 lines

  1. --This example simulates a falling object with air friction proportional to the square of its velocity. The technique used is inefficient compared with fancier methods for numerical solutions of differential equations, but it is very easy to program. See example "projectile" for a similar problem in two dimensions.
  2.  
  3. init = v:=0,t:=0  -- initial conditions
  4.  
  5. stepto(stop) = init when stop=0,
  6.                (v:=v+a*dt,
  7.                 t:=t+dt) while t<stop
  8.  
  9. f=m*g-k*v^2   -- gravity - air friction
  10. a=f/m
  11.             
  12. g=9.8        -- accelleration due to gravity
  13. k=2          -- friction coefficient
  14. m=300        -- mass of object
  15. dt=.05       -- time step for simulation
  16.  
  17. vsim(t1) = stepto(t1),v  --run to t1, return v
  18.  
  19. Xmin=0; Xmax=10  -- plot v vs time for 10 sec
  20. plot vsim(X)
  21.  
  22. -- compare to analytical solution
  23. van(t)=sqrt(m*g/k)*tanh(sqrt(g*k/m)*t)
  24. plot van(X)
  25.  
  26. tanh(u)=(exp(u)-exp(-u))/(exp(u)+exp(-u))
  27.